package com.sun.lotter.luck;

import java.util.ArrayList;
import java.util.Date;
import java.util.Random;
import java.util.regex.Pattern;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

import com.sun.base.BasePlayType;
import com.sun.bata.LotterData;
import com.sun.bata.MakeLotterNumber;
import com.sun.lotter.LotterNumberDialog;
import com.sun.lotter.R;
import com.tools.SysInterfacePhone;

public class LuckPlayPage4 extends BasePlayType {
	EditText editText_familyname, editText_name;

	public LuckPlayPage4(LuckLotterActivity context) {
		super(context);
		LayoutInflater.from(context).inflate(R.layout.luck_layout_4, this);

		editText_familyname = (EditText) findViewById(R.id.EditText_Familyname);
		editText_name = (EditText) findViewById(R.id.EditText_Name);
		findViewById(R.id.button1).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				LuckPlayPage4.this.onClick();
			}
		});
	}

	@Override
	public void onEvent(String e) {
		// TODO Auto-generated method stub

	}

	public void onClick() {

		String name = editText_name.getText().toString();
		String familyname = editText_familyname.getText().toString();
		if (!check_Chinese("^[\u4E00-\u9FA5]{1,4}$", name)) {
			SysInterfacePhone.invoker().createToast(getContext(), "你输入的‘名’有误,\n名为最长为四位的汉字,且不能为空！").show();
		} else if (!check_Chinese("^[\u4E00-\u9FA5]{1,2}$", familyname)) {
			SysInterfacePhone.invoker().createToast(getContext(),"你输入的‘姓’有误,\n姓为最长为二位的汉字,且不能为空！");
			
		} else {

			MakeLotterNumber makeLotterNumber = new MakeLotterNumber();
			Random rand = makeLotterNumber.getRandom(
					new Date(System.currentTimeMillis()), 0, null,
					LotterData.DOUBLECOLORBALL, 0, 4);
			ArrayList<String> list = makeLotterNumber.makeLotterNumbers(rand,
					LotterData.DOUBLECOLORBALL, 0, 1);
			for (String string : list) {
				System.out.println(string);
			}
			new LotterNumberDialog(getContext(), list,
					LotterData.DOUBLECOLORBALL, 0).show();
		}
	}

	private boolean check_Chinese(String arg0, String arg1) {
		if (Pattern.compile(arg0).matcher(arg1).matches()) {
			return true;
		}
		return false;
	}
}
